<?php

namespace app\Admin\validate;

use think\Validate;

// 验证器
class Admin extends Validate
{
    protected $failException = false;
    protected $rule = [
        'id' => 'require',
        'username' => 'require|unique:admin|max:25',   // unique:admin 代表这个数据添加时在admin表里面确保唯一
        'phone' => 'require|unique:admin|mobile',
        'email' => 'require|email|unique:admin',
        'role' => 'require',
        'password' => 'require|min:6|max:16',
        'repassword' => 'require|confirm:password',
        'status'=>'require'
    ];
    protected $message = [
        'id.require' => 'id值必须传入',
        'username.require' => '管理员名称必须填写',
        'username.unique' => '管理员名称已存在',
        'username.max' => '管理员名称长度不能超过25个字符',
        'phone.require' => '手机号必须填写',
        'phone.mobile' => '请输入正确的手机号',
        'phone.unique' => '手机号已存在',
        'email.require' => '请输入邮箱',
        'email.email' => '请输入正确的邮箱',
        'email.unique' => '邮箱已存在',
        'role.require' => '请选择一个角色',
        'password.require' => '密码必须填写',
        'password.min' => '密码不能少于6个字符',
        'password.max' => '密码不能超过16个字符',
        'repassword.require' => '确认密码必须填写',
        'repassword.confirm' => '两次密码输入不一致',
        'status.require'=>'状态未传入'
    ];

    protected $scene = [
        // 针对场景验证
        'add_admin' => ['username', 'phone', 'email', 'role', 'password', 'repassword','status'],
        'update_admin' => ['id', 'username', 'phone', 'email', 'role', 'password', 'repassword','status'],
        'del_admin' => ['id'],
        'login_admin'=>['username', 'password'],
    ];
}